Get new issues of The GitHub Insider in your inbox. Sign up now →
The GitHub Insider
Don’t miss these simple tricks for powerful results ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ 
GitHub

When it comes to AI, the sky's the limit. ☀️

By now, many of us are familiar with the basics of prompt engineering, i.e. providing GitHub Copilot with context about our project so we get better, more relevant answers.

But did you know there is so much more you can do to provide the tool context? In this edition of The GitHub Insider, we’re going to explore some new, super fancy (though still super simple!) prompt strategies to make Copilot work as hard as possible for you and your project.

Let’s go!

1. Q&A prompt 👷

This is where you get Copilot to prompt you so you can effectively prompt Copilot. This might sound like something out of Inception, but hear me out: this strategy is perfect if you forget to include important details in your initial prompt (which I do all the time).

Let’s explore how this works! 👇

Let’s say you want a recommendation from Copilot on how to structure your project inside VS Code. In your main workspace window, you might see a list of all your project files on the right. If you’re like me, your files are often in no particular order, organized haphazardly like a junk drawer.

That’s OK, but having a better organized folder structure will make your project easier to manage and, even better, easier to collaborate with others.

This is somewhere Copilot can be helpful. You can ask Copilot to propose a folder structure to help you organize your project. To do this, we’ll use the @workspace agent in Copilot Chat to ask Copilot. This agent will pass all the information about your current project (including the existing files and folders) along with the prompt.

Additionally, you can ask Copilot to ask you a series of yes/no questions to help it provide a better recommendation.

Check out the questions it provided:

Answer each one, including the question number in your responses.

(You might get some questions that aren’t yes/no, but that’s the nature of good ol’ AI so just roll with it.)

And then, voila! You get a nice recommendation for how to structure your project!

The magic of the Q&A prompt is that it helps you put in all the details you would initially have only if you had thought of them.

So don’t worry about having the perfect prompt the first time; use the Q&A prompt to have Copilot prompt you to give it the best prompt.

2. Pros and cons prompt 👍👎🏽

In programming, there’s rarely a single “right” way to do anything.

In our above example, I went ahead and started to implement Copilot’s recommendations for structuring my project, creating folders for my API (api), my database (db), and my static files (public).

Inside my db folder, I have a TypeScript file where I’ve written my database connection class (db.ts), but I’m not sure if this is the right way to connect with this app. Luckily, I can ask Copilot for suggestions on how to implement this logic, but this time, I’m going to ask for the pros and cons of each suggestion.

I’ll go one step further and affix the TypeScript file to the prompt for even more context (use #file:filename.ext to attach your file).

And voila! You get suggestions and pros and cons of each method!

Remember, there’s no one right way to do anything—so use a pros and cons prompt and have Copilot give you several options so you can pick the best one for you.

3. Stepwise chain of thought 🔗

Sometimes, the best way of getting the best prompt is to break things down into smaller steps. We can even use Copilot to do this, by asking it to give us a solution one step at a time.

For instance, normally, if you want to refactor a code file and clean it up, you can ask Copilot (remember to replace vehiclesService.ts with the file you want refactored):

Help me refactor the code in #file:vehiclesService.ts

But you’ll get a pretty verbose response and it will try to do the entire refactoring in one shot, which is way too many changes to validate all at once.

So instead, ask it to do one step at a time by asking:

Help me refactor the code in #file:vehiclesService.ts. Go one step at a time. Do not move to the next step until I give the keyword “next”. Begin.

In this way, it’ll only work on one change at a time, and you can make sure each step looks good before hitting “next”.

Remember, the AI assistants are our assistants. That means they are designed to follow our instructions. And unlike human assistants or pair-programmers, Copilot isn’t going to be frustrated if you ask it to do something over and over again in smaller steps.

4. Role prompt 👩🏽‍🏫

Interested in learning Rust? React? Data science? Or really any other techy thing under the sun?

Well, good news, with Copilot, you can – and easily!

Copilot is very good at role playing, you just need to prompt it to take on the right role. Let’s say you want to learn about regular expressions. You could just ask Copilot about the topic, but what if we instead ask Copilot to role play as a teacher who is skilled at making complex topics simple and come up with fun exercises? In this case, let’s also ask it to teach students to be proficient in regular expressions.

We can take cues from our previous tip and ask it to move us through one step at a time, waiting for the “student” to provide a correct answer before moving on to the next lesson or concept. We can also have the prompt ensure that if the “student” gives the wrong answer, Copilot should offer up a hint.

Then watch it go!

As with our other tips, don’t be afraid to be descriptive and specific with what role you want Copilot to take on. Remember, the more specific you can be, the better the AI is going to be able to provide you with the results you want.

And have fun exploring! If you come up with a prompt that gets you really good results, you might want to keep it in a text file of your favorite prompts that you can augment in the future.

Try it out and learn something new today!

Get started with GitHub Copilot


✨ This newsletter was written by Christina Warren and produced by Gwen Davis. ✨

More to explore 🌎



Join our GitHub Copilot conversations 🤖

Visit our community forum to see what people are saying + offer your own two cents.

Visit now



Stay updated on GitHub products 📦

Discover the latest ships, launches, and improvements in our Changelog.

Explore now



Take our open source survey 💡

We’re working with the Linux Foundation and researchers at Harvard University to learn more about how organizations fund open source projects.

Take the survey now



Subscribe to our LinkedIn newsletter 🚀

Do your best work on GitHub. Subscribe to our LinkedIn newsletter, Branching Out_.

Sign up now



Attend GitHub Universe 🪐

Experience the world’s fair of software at the historic Fort Mason Center, October 29-20.

Buy your tickets for 20% off now




GitHub

The world’s leading AI-powered developer platform.